package com.newviews.tcmip.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.newviews.tcmip.common.constant.CommonConsts;
import com.newviews.tcmip.common.enums.UiElCodeEnums;
import com.newviews.tcmip.common.model.PageModel;
import com.newviews.tcmip.common.model.ResultModel;
import com.newviews.tcmip.dao.EtcmHerbExMapper;
import com.newviews.tcmip.dao.EtcmPxExMapper;
import com.newviews.tcmip.pojo.po.*;
import com.newviews.tcmip.pojo.vo.EtcmCommonBaseInfoRespVO;
import com.newviews.tcmip.pojo.vo.export.EtcmCommonExportReqVO;
import com.newviews.tcmip.service.inf.*;
import com.newviews.tcmip.web.vo.etcmherb.download.EtcmHerbByHerbExportReqVO;
import com.newviews.tcmip.web.vo.etcmherb.download.EtcmHerbByIngrExportReqVO;
import com.newviews.tcmip.web.vo.etcmherb.download.EtcmHerbDetailsExportReqVO;
import com.newviews.tcmip.web.vo.etcmherb.download.EtcmHerbExportReqVO;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.*;
import java.util.stream.Collectors;

/**
 * <p>
 * 中草药库 服务实现类
 * </p>
 *
 * @author lxc
 * @since 2024-02-29
 */
@Service
public class EtcmHerbExServiceImpl extends ServiceImpl<EtcmHerbExMapper, EtcmHerbExPo> implements EtcmHerbExServiceInf {
    @Resource
    private EtcmHerbServiceInf etcmHerbServiceInf;
    @Resource
    private EtcmHerbExMapper etcmHerbExMapper;

    @Resource
    private EtcmIngrExServiceInf etcmIngrExServiceInf;
    @Resource
    private EtcmExperimentalRecordsExServiceInf etcmExperimentalRecordsExServiceInf;
    @Resource
    private EtcmDiseaseExServiceInf etcmDiseaseExServiceInf;
    @Resource
    private EtcmPxExServiceInf etcmPxExServiceInf;

    @Resource
    private EtcmPxExMapper etcmPxExMapper;
    @Override
    public List<Map<String, String>> downloadHerb(EtcmHerbExportReqVO reqVO) {
        QueryWrapper<EtcmHerbExPo> wrapper = new QueryWrapper<>();

        if (StringUtils.isBlank(reqVO.getFlavor()) && StringUtils.isBlank(reqVO.getProperty()) && StringUtils.isBlank(reqVO.getMeridians())){
            return new ArrayList<>();
        }

        if (StringUtils.isNotBlank(reqVO.getFlavor())){
            wrapper.in("t2.flavor_code",reqVO.getFlavor().split(","));
        }

        if (StringUtils.isNotBlank(reqVO.getProperty())){
            wrapper.in("t3.property_code",reqVO.getProperty().split(","));
        }

        if (StringUtils.isNotBlank(reqVO.getMeridians())){
            wrapper.in("t4.meridians_code",reqVO.getMeridians().split(","));
        }
        if (StringUtils.isNotBlank(reqVO.getContent())){
            wrapper.and(w->w.like( "t1.herb_zh_name", reqVO.getContent())
                    .or().like( "t1.herb_zh_name_py", reqVO.getContent())
                    .or().like( "t1.herb_zh_name_wb", reqVO.getContent())
                    .or().like( "t1.herb_zh_name_abb", reqVO.getContent())
                    .or().like( "t1.herb_en_name", reqVO.getContent())
                    .or().like( "t1.herb_en_name_abb", reqVO.getContent())
                    .or().like( "t1.herb_latin_name", reqVO.getContent())
                    .or().like( "t1.herb_latin_name_abb", reqVO.getContent())
                    .or().like( "t1.herb_name_alias", reqVO.getContent())
            );
        }

        wrapper.eq("t1.status", CommonConsts.COMMON_YES);
        if(reqVO.getSortType().toLowerCase().equals(CommonConsts.SORT_TYPE_ASC.toLowerCase())){
            wrapper.orderByAsc("s1.herb_id");
        }else {
            wrapper.orderByDesc("s1.herb_id");
        }
        wrapper.groupBy("s1.herb_id");
        List<EtcmHerbExPo> page = etcmHerbExMapper.getHerbDownload(wrapper,reqVO.getUiTypeCode(), reqVO.getLangCode());


       // List<Map<String,String>> resList = new ArrayList<>();
        Map<String,List<EtcmHerbExPo>> disMap = new HashMap<>(16);
        for (EtcmHerbExPo record : page) {
            List<EtcmHerbExPo> disList = new ArrayList<>();

            String[] uiElCodeList = record.getUiElCode().split("\\|\\|");
            String[] herbExConList = record.getHerbExCon().split("\\|\\|");
            for (int i = 0; i < uiElCodeList.length; i++) {
                EtcmHerbExPo etcmHerbExPo = new EtcmHerbExPo();

                for (int j = 0; j < herbExConList.length; j++) {
                    if (i == j){
                        etcmHerbExPo.setUiElCode(uiElCodeList[i]);
                        etcmHerbExPo.setHerbExCon(herbExConList[j]);

                    }
                }
                disList.add(etcmHerbExPo);
            }

            disMap.put(record.getHerbId(),disList);
        }


        List<EtcmUiElPo> etcmUiElPos = etcmPxExMapper.getUIElName(reqVO.getUiTypeCode(),reqVO.getLangCode());
        etcmUiElPos = etcmUiElPos.stream().filter(etcmUiElPo -> etcmUiElPo.getUiElSort() != 3).collect(Collectors.toList());
        List<Map<String, String>> resultList = new ArrayList<>();

        for (String key : disMap.keySet()) {
            Map<String,String> mapRes=new HashMap<>(16);
            List<EtcmHerbExPo> values = disMap.get(key);
            List<String> collect = values.stream().map(EtcmHerbExPo::getUiElCode).collect(Collectors.toList());
            for (EtcmUiElPo etcmUiElPo : etcmUiElPos) {
                if (collect.contains(etcmUiElPo.getUiElCode())){
                    for (EtcmHerbExPo etcmHerbExPo : values) {
                        if (etcmUiElPo.getUiElCode().equals(etcmHerbExPo.getUiElCode())){
                            mapRes.put(etcmHerbExPo.getUiElCode(), etcmHerbExPo.getHerbExCon());
                        }
                    }
                }else {
                    mapRes.put(etcmUiElPo.getUiElCode(), "");
                }

            }

            resultList.add(mapRes);
        }

        if(reqVO.getSortType().toLowerCase().equals(CommonConsts.SORT_TYPE_ASC.toLowerCase())){
            Collections.sort(resultList, new Comparator<Map<String, String>>() {
                @Override
                public int compare(Map<String, String> o1, Map<String, String> o2) {
                    return String.valueOf(o1.get("100716826576556928")).compareTo(String.valueOf(o2.get("100716826576556928")));
                }
            });
        }else {
            Collections.sort(resultList, new Comparator<Map<String, String>>() {
                @Override
                public int compare(Map<String, String> o1, Map<String, String> o2) {
                    return -String.valueOf(o1.get("100716826576556928")).compareTo(String.valueOf(o2.get("100716826576556928")));
                }
            });
        }

        return resultList;
    }

    @Override
    public List<Map<String, String>> downloadHerbDetails(EtcmHerbDetailsExportReqVO reqVO) {
        List<EtcmHerbExPo> exList = etcmHerbExMapper.getList(new QueryWrapper<EtcmHerbExPo>()
                .eq("t1.status", CommonConsts.COMMON_YES)
                .eq("t2.status", CommonConsts.COMMON_YES)
                .eq("t1.herb_id", reqVO.getHerbId())
                .eq("t2.language_code", reqVO.getLangCode())
                .eq("t2.ui_type_code", reqVO.getUiTypeCode())
                .isNotNull("t1.herb_ex_con")
                .orderByAsc("t2.ui_el_sort")
        );
        List<Map<String,String>> resList = new ArrayList<>();
        Map<String,String> map = new LinkedHashMap<>();
        for(EtcmHerbExPo etcmHerbExPo:exList){
            map.put(etcmHerbExPo.getUiElName(),etcmHerbExPo.getHerbExCon());
        }
        resList.add(map);
        return resList;
    }

    @Override
    public List<Map<String, String>> downloadHerbIngr(EtcmHerbByIngrExportReqVO reqVO) {
        QueryWrapper<EtcmIngrPo> wrapper = new QueryWrapper<>();
        wrapper.eq("t1.herb_id",reqVO.getHerbId());
        wrapper.eq("t1.status",CommonConsts.COMMON_YES);
        wrapper.eq("t2.status",CommonConsts.COMMON_YES);
//        wrapper.in(StringUtils.isNotBlank(reqVO.getMetabolicStability()),"t2."+EtcmIngrPo.INGR_METABOLIC_STABILITY_CODE,reqVO.getMetabolicStability().split(","));
//        wrapper.in(StringUtils.isNotBlank(reqVO.getTransportMode()),"t2."+EtcmIngrPo.INGR_TRANSPORT_MODE_CODE,reqVO.getTransportMode().split(","));
//        wrapper.in(StringUtils.isNotBlank(reqVO.getHalflifePeriod()),"t2."+EtcmIngrPo.INGR_HALF_LIFE_PERIOD_CODE,reqVO.getHalflifePeriod().split(","));


        if (StringUtils.isNotBlank(reqVO.getIngrBbb())){
            wrapper.in("t2.ingr_bbb_code",reqVO.getIngrBbb().split(","));
        }
        if (StringUtils.isNotBlank(reqVO.getIngrCaco2())){
            wrapper.in("t2.ingr_caco2_code",reqVO.getIngrCaco2().split(","));
        }
        if (StringUtils.isNotBlank(reqVO.getIngrHia())){
            wrapper.in("t2.ingr_hia_code",reqVO.getIngrHia().split(","));
        }
        if (StringUtils.isNotBlank(reqVO.getIngrHob())){
            wrapper.in("t2.ingr_hob_code",reqVO.getIngrHob().split(","));
        }

        if (StringUtils.isNotBlank(reqVO.getContent())){
            wrapper.and(w->w.like( "t2."+EtcmIngrPo.INGR_ZH_NAME, reqVO.getContent())
                    .or().like("t2."+EtcmIngrPo.INGR_ZH_NAME_ABB, reqVO.getContent())
                    .or().like("t2."+EtcmIngrPo.INGR_EN_NAME, reqVO.getContent())
                    .or().like("t2."+EtcmIngrPo.INGR_EN_NAME_ABB, reqVO.getContent())
                    .or().like("t2."+EtcmIngrPo.INGR_LATIN_NAME, reqVO.getContent())
                    .or().like("t2."+EtcmIngrPo.INGR_LATIN_NAME_ABB, reqVO.getContent())
                    .or().like("t2."+EtcmIngrPo.INGR_NAME_ALIAS, reqVO.getContent()));
        }
        if(reqVO.getSortType().toLowerCase().equals(CommonConsts.SORT_TYPE_ASC.toLowerCase())){
            wrapper.orderByAsc("t2.ingr_code");
        }else {
            wrapper.orderByDesc("t2.ingr_code");
        }
        List<EtcmIngrPo> list = etcmHerbExMapper.getListByIngr(wrapper);

        List<Map<String,String>> resList = new ArrayList<>();
        for (EtcmIngrPo record : list) {
            HashMap<String,String> map = new HashMap<>();
            List<EtcmIngrExPo> exList = etcmIngrExServiceInf.list(new QueryWrapper<EtcmIngrExPo>()
                    .eq(EtcmIngrExPo.STATUS, CommonConsts.COMMON_YES)
                    .eq(EtcmIngrExPo.INGR_ID, record.getIngrCode())
                    .eq("language_code",reqVO.getLangCode())
                    .eq("ui_type_code",CommonConsts.UI_TYPE_CODE_INGR)
            );

            if(CommonConsts.LANG_CODE_ENG.toLowerCase().equals(reqVO.getLangCode().toLowerCase())) {
                map.put(UiElCodeEnums.HERB_NAME.getUiElCode(), record.getHerbEnName());
            }
            if(CommonConsts.LANG_CODE_CHN.toLowerCase().equals(reqVO.getLangCode().toLowerCase())) {
                map.put(UiElCodeEnums.HERB_NAME.getUiElCode(), record.getHerbZhName());
            }

            for (EtcmIngrExPo etcmIngrExPo : exList) {
                map.put(etcmIngrExPo.getUiElCode(),etcmIngrExPo.getIngrExCon());
            }
            resList.add(map);
        }
        return resList;
    }



    @Override
    public List<Map<String, String>> downloadAssociatedDiseases(EtcmHerbByHerbExportReqVO reqVO) {
        QueryWrapper<EtcmHerbDiseasePo> wrapper = new QueryWrapper<>();
        if (StringUtils.isNotBlank(reqVO.getContent())){
//            if (CommonConsts.LANG_CODE_ENG.equals(reqVO.getLangCode())){
//                wrapper.like("t2.herb_en_name",reqVO.getContent());
//            }
//
//            if (CommonConsts.LANG_CODE_CHN.equals(reqVO.getLangCode())){
//                wrapper.like("t2.herb_zh_name",reqVO.getContent());
//            }
            wrapper.and(w->w.like( "t3.disease_zh_name", reqVO.getContent())
                    .or().like( "t3.disease_zh_name_py", reqVO.getContent())
                    .or().like( "t3.disease_zh_name_wb", reqVO.getContent())
                    .or().like( "t3.disease_zh_name_abb", reqVO.getContent())
                    .or().like( "t3.disease_en_name", reqVO.getContent())
                    .or().like( "t3.disease_en_name_abb", reqVO.getContent())
                    .or().like( "t3.disease_latin_name", reqVO.getContent())
                    .or().like( "t3.disease_latin_name_abb", reqVO.getContent())
                    .or().like( "t3.disease_name_alias", reqVO.getContent()));
        }
        wrapper.eq("t1.herb_id",reqVO.getHerbId());
//        wrapper.orderByAsc("t1.herb_disease_distance");
        wrapper.last("limit 200");

        List<EtcmHerbDiseasePo> page = etcmHerbExMapper.getPageByAssociatedDiseases(wrapper);
        List<EtcmUiElPo> uiElNameList = etcmPxExMapper.getUIElName(reqVO.getUiTypeCode(), reqVO.getLangCode());

        List<Map<String,String>> resMap = new ArrayList<>();

        if(reqVO.getSortType().toLowerCase().equals(CommonConsts.SORT_TYPE_ASC.toLowerCase())){
            page = page.stream().sorted(Comparator.comparing(EtcmHerbDiseasePo::getHerbDiseaseDistance)).collect(Collectors.toList());
        }else {
            page = page.stream().sorted(Comparator.comparing(EtcmHerbDiseasePo::getHerbDiseaseDistance).reversed()).collect(Collectors.toList());
        }


        page.forEach(etcmHerbHerbPo -> {
            Map<String, String> stringStringMap = getStringStringMap(reqVO.getLangCode(), etcmHerbHerbPo, uiElNameList);
            resMap.add(stringStringMap);
        });
        return resMap;
    }

    @Override
    public List<Map<String, String>> downloadPx(EtcmHerbDetailsExportReqVO reqVO) {
        QueryWrapper<EtcmPxPo> wrapper = new QueryWrapper<>();
        wrapper.eq("t1.herb_id",reqVO.getHerbId());
        wrapper.eq("t1.status",CommonConsts.COMMON_YES);
        wrapper.eq("t2.status",CommonConsts.COMMON_YES);
        if (StringUtils.isNotBlank(reqVO.getContent())){
            wrapper.and(w->w.like("t2.px_zh_name", reqVO.getContent())
                    .or().like("t2.px_zh_name_py", reqVO.getContent())
                    .or().like("t2.px_zh_name_wb", reqVO.getContent())
                    .or().like("t2.px_zh_name_abb", reqVO.getContent())
                    .or().like("t2.px_en_name", reqVO.getContent())
                    .or().like("t2.px_en_name_abb", reqVO.getContent())
                    .or().like("t2.px_latin_name", reqVO.getContent())
                    .or().like("t2.px_latin_name_abb", reqVO.getContent()));
        }
        if(reqVO.getSortType().toLowerCase().equals(CommonConsts.SORT_TYPE_ASC.toLowerCase())){
            wrapper.orderByAsc("t2.px_code");
        }else {
            wrapper.orderByDesc("t2.px_code");
        }
        List<EtcmPxPo> list = etcmHerbExMapper.getListByPx(wrapper);

        List<Map<String,String>> resList = new ArrayList<>();
        for (EtcmPxPo record : list) {
            HashMap<String,String> map = new HashMap<>();
            List<EtcmPxExPo> exList = etcmPxExServiceInf.list(new QueryWrapper<EtcmPxExPo>()
                    .eq(EtcmPxExPo.STATUS, CommonConsts.COMMON_YES)
                    .eq(EtcmPxExPo.PX_ID, record.getPxCode())
                    .eq("language_code",reqVO.getLangCode())
                    .eq("ui_type_code",reqVO.getUiTypeCode())
            );
            for (EtcmPxExPo etcmPxExPo : exList) {
                map.put(etcmPxExPo.getUiElCode(),etcmPxExPo.getPxExCon());
            }
            resList.add(map);
        }
        return resList;
    }

    @Override
    public List<Map<String, String>> downloadCombinedHerbs(String herbId, String sortType, String content, String langCode, String uiTypeCode,String searchName) {
        QueryWrapper<EtcmHerbHerbPo> wrapper = new QueryWrapper<>();
        if (StringUtils.isNotBlank(content)){
//            if (CommonConsts.LANG_CODE_ENG.equals(langCode)){
//                wrapper.like("t2.herb_en_name",content);
//            }
//
//            if (CommonConsts.LANG_CODE_CHN.equals(langCode)){
//                wrapper.like("t2.herb_zh_name",content);
//            }
            wrapper.and(w->w.like( "t3.herb_zh_name", searchName)
                    .or().like( "t3.herb_zh_name_py", searchName)
                    .or().like( "t3.herb_zh_name_wb", searchName)
                    .or().like( "t3.herb_zh_name_abb", searchName)
                    .or().like( "t3.herb_en_name", searchName)
                    .or().like( "t3.herb_en_name_abb", searchName)
                    .or().like( "t3.herb_latin_name", searchName)
                    .or().like( "t3.herb_latin_name_abb", searchName)
                    .or().like( "t3.herb_name_alias", searchName));
        }
        wrapper.eq("t1.herb_code",herbId);
        //wrapper.orderByAsc("t1.herb_herb_distance");
        wrapper.last("limit 200");

        List<EtcmHerbHerbPo> page = etcmHerbExMapper.getPageByCombinedHerbs(wrapper);
        List<EtcmUiElPo> uiElNameList = etcmPxExMapper.getUIElName(uiTypeCode, langCode);

        List<Map<String,String>> resMap = new ArrayList<>();


        if(sortType.toLowerCase().equals(CommonConsts.SORT_TYPE_ASC.toLowerCase())){
            page = page.stream().sorted(Comparator.comparing(EtcmHerbHerbPo::getHerbHerbDistance)).collect(Collectors.toList());
        }else {
            page = page.stream().sorted(Comparator.comparing(EtcmHerbHerbPo::getHerbHerbDistance).reversed()).collect(Collectors.toList());
        }

        page.forEach(etcmHerbHerbPo -> {
            Map<String, String> stringStringMap = getStringStringMap(langCode, etcmHerbHerbPo, uiElNameList);
            resMap.add(stringStringMap);
        });

        return resMap;
    }

    @Override
    public List<Map<String, String>> downloadHerbTarget(String herbId, String content, String uiTypeCode, String langCode, String sortType, String type) {
        if (StringUtils.isBlank(type)){
            return new ArrayList<>();
        }
        QueryWrapper<EtcmTargetPo> wrapper=new QueryWrapper<>();
        wrapper.eq("t5.language_code", langCode);
        wrapper.in("t3.target_type_code", type.split(","));
        if(com.newviews.tcmip.common.utils.StringUtils.isNotBlank(content)){
            wrapper.and(w->w.like("t3.target_zh_name", content)
                    .or().like("t3.target_zh_name_py", content)
                    .or().like("t3.target_zh_name_wb", content)
                    .or().like("t3.target_zh_name_abb", content)
                    .or().like("t3.target_en_name", content)
                    .or().like("t3.target_en_name_abb", content)
                    .or().like("t3.target_latin_name", content)
                    .or().like("t3.target_latin_name_abb", content)
                    .or().like("t3.target_name_alias", content));
        }
        if(sortType.equalsIgnoreCase(CommonConsts.SORT_TYPE_ASC)){
            wrapper.orderByAsc("t2.target_id");
        }else {
            wrapper.orderByDesc("t2.target_id");
        }
        //wrapper.isNotNull("t3.id");
        List<EtcmIngrTargetPo> pageTarget = etcmHerbExMapper.getDownloadHerbTarget(wrapper,herbId);
        List<Map<String,String>> resultList=new ArrayList<>();

        List<EtcmUiElPo> uiElName = etcmPxExMapper.getUIElName(uiTypeCode, langCode);
        pageTarget.forEach(etcmIngrTargetPo -> {
            Map<String, String> map = getStringStringMap(langCode, etcmIngrTargetPo, uiElName);
            resultList.add(map);
        });
        return resultList;
    }

    @Override
    public List<Map<String, String>> downloadExperimentalRecords(String herbId, String content, String uiTypeCode, String langCode, String sortType) {
        QueryWrapper<EtcmExperimentalRecordsPo> wrapper=new QueryWrapper<>();
        if(com.newviews.tcmip.common.utils.StringUtils.isNotBlank(content)){
            wrapper.and(w->w.like("t3.er_zh_name", content)
                    .or().like("t3.er_zh_name_py", content)
                    .or().like("t3.er_zh_name_wb", content)
                    .or().like("t3.er_zh_name_abb", content)
                    .or().like("t3.er_en_name", content)
                    .or().like("t3.er_en_name_abb", content)
                    .or().like("t3.er_latin_name", content)
                    .or().like("t3.er_latin_name_abb", content)
                    .or().like("t3.er_name_alias", content));
        }
        if(sortType.equalsIgnoreCase(CommonConsts.SORT_TYPE_ASC)){
            wrapper.orderByAsc("t2.er_id");
        }else {
            wrapper.orderByDesc("t2.er_id");
        }
        List<EtcmExperimentalRecordsIngrPo> pageEr = etcmHerbExMapper.getListErDownload(wrapper, herbId);
        List<Map<String,String>> resultList=new ArrayList<>();

        List<EtcmUiElPo> uiElName = etcmPxExMapper.getUIElName(uiTypeCode, langCode);
        for (EtcmExperimentalRecordsIngrPo record : pageEr) {
            Map<String, String> map = getStringStringMap(langCode, record, uiElName);
            resultList.add(map);
        }
        return resultList;
    }

    private static Map<String, String> getStringStringMap(String langCode, EtcmExperimentalRecordsIngrPo recordsIngrPo, List<EtcmUiElPo> uiElNameList) {
        Map<String,String> map = new HashMap<>(16);
        for (EtcmUiElPo etcmUiElPo : uiElNameList) {
            switch (etcmUiElPo.getUiElSort()){
                case 1:
                    map.put(etcmUiElPo.getUiElCode(), recordsIngrPo.getErId());
                    break;
                case 2:
                    if (CommonConsts.LANG_CODE_ENG.equals(langCode)){
                        map.put(etcmUiElPo.getUiElCode(), recordsIngrPo.getErEnName());
                    }
                    if (CommonConsts.LANG_CODE_CHN.equals(langCode)){
                        map.put(etcmUiElPo.getUiElCode(), recordsIngrPo.getErZhName());
                    }
                    break;
                case 3:
                    map.put(etcmUiElPo.getUiElCode(), recordsIngrPo.getPubchemCid());
                    break;
                case 5:
                    map.put(etcmUiElPo.getUiElCode(), recordsIngrPo.getMolecularFormula());
                    break;
                case 6:
                    map.put(etcmUiElPo.getUiElCode(), recordsIngrPo.getMolecularWeight());
                    break;
                case 7:
                    map.put(etcmUiElPo.getUiElCode(), recordsIngrPo.getConcentration());
                    break;
                case 8:
                    map.put(etcmUiElPo.getUiElCode(),recordsIngrPo.getCelllines());
                    break;
                case 9:
                    map.put(etcmUiElPo.getUiElCode(),recordsIngrPo.getOrangism());
                default:
            }

        }
        return map;
    }

    private static Map<String, String> getStringStringMap(String langCode, EtcmIngrTargetPo etcmIngrTargetPo, List<EtcmUiElPo> uiElNameList) {
        Map<String,String> map = new HashMap<>(16);
        for (EtcmUiElPo etcmUiElPo : uiElNameList) {
            switch (etcmUiElPo.getUiElSort()){
                case 1:
                    map.put(etcmUiElPo.getUiElCode(), etcmIngrTargetPo.getTargetId());
                    break;
                case 2:
                    map.put(etcmUiElPo.getUiElCode(), etcmIngrTargetPo.getSymbolIdHum());
                    break;
                case 3:
                    if (CommonConsts.LANG_CODE_ENG.equals(langCode)){
                        map.put(etcmUiElPo.getUiElCode(), etcmIngrTargetPo.getIngrEnName());
                    }
                    if (CommonConsts.LANG_CODE_CHN.equals(langCode)){
                        map.put(etcmUiElPo.getUiElCode(), etcmIngrTargetPo.getIngrZhName());
                    }
                    break;
                case 4:
                    map.put(etcmUiElPo.getUiElCode(), etcmIngrTargetPo.getTypeName());
                    break;
                case 6:
                    map.put(etcmUiElPo.getUiElCode(), etcmIngrTargetPo.getEntrezIdHum());
                    break;
                case 7:
                    map.put(etcmUiElPo.getUiElCode(),etcmIngrTargetPo.getUniprotIdHum());
                default:
            }

        }
        return map;
    }

    private static Map<String, String> getStringStringMap(String langCode, EtcmHerbHerbPo etcmHerbHerbPo, List<EtcmUiElPo> uiElNameList) {
        Map<String,String> map = new HashMap<>(16);
        for (EtcmUiElPo etcmUiElPo : uiElNameList) {
            switch (etcmUiElPo.getUiElSort()){
                case 1:
                    map.put(etcmUiElPo.getUiElCode(), etcmHerbHerbPo.getHerbCode() + "-" + etcmHerbHerbPo.getTargetHerbCode());
                    break;
                case 2:
                    if (CommonConsts.LANG_CODE_ENG.equals(langCode)){
                        map.put(etcmUiElPo.getUiElCode(), etcmHerbHerbPo.getHerbEnName());
                    }
                    if (CommonConsts.LANG_CODE_CHN.equals(langCode)){
                        map.put(etcmUiElPo.getUiElCode(), etcmHerbHerbPo.getHerbZhName());
                    }
                    break;

                case 3:
                    if (CommonConsts.LANG_CODE_ENG.equals(langCode)){
                        map.put(etcmUiElPo.getUiElCode(), etcmHerbHerbPo.getTargetHerbEnName());
                    }
                    if (CommonConsts.LANG_CODE_CHN.equals(langCode)){
                        map.put(etcmUiElPo.getUiElCode(), etcmHerbHerbPo.getTargetHerbZhName());
                    }
                    break;
                case 4:
                    map.put(etcmUiElPo.getUiElCode(), etcmHerbHerbPo.getHerbHerbDistance());
                    break;
                case 5:
                    map.put(etcmUiElPo.getUiElCode(),"");
                default:
            }

        }
        return map;
    }


    private static Map<String, String> getStringStringMap(String langCode, EtcmHerbDiseasePo etcmHerbDiseasePo, List<EtcmUiElPo> uiElNameList) {
        Map<String,String> map = new HashMap<>(16);
        for (EtcmUiElPo etcmUiElPo : uiElNameList) {
            switch (etcmUiElPo.getUiElSort()){
                case 1:
                    map.put(etcmUiElPo.getUiElCode(), etcmHerbDiseasePo.getHerbId() + "-" + etcmHerbDiseasePo.getDiseaseId());
                    break;
                case 2:
                    if (CommonConsts.LANG_CODE_ENG.equals(langCode)){
                        map.put(etcmUiElPo.getUiElCode(), etcmHerbDiseasePo.getHerbEnName());
                    }
                    if (CommonConsts.LANG_CODE_CHN.equals(langCode)){
                        map.put(etcmUiElPo.getUiElCode(), etcmHerbDiseasePo.getHerbZhName());
                    }
                    break;

                case 3:
                    if (CommonConsts.LANG_CODE_ENG.equals(langCode)){
                        map.put(etcmUiElPo.getUiElCode(), etcmHerbDiseasePo.getDiseaseEnName());
                    }
                    if (CommonConsts.LANG_CODE_CHN.equals(langCode)){
                        map.put(etcmUiElPo.getUiElCode(), etcmHerbDiseasePo.getDiseaseZhName());
                    }
                    break;
                case 4:
                    map.put(etcmUiElPo.getUiElCode(), etcmHerbDiseasePo.getHerbDiseaseDistance());
                    break;
                case 5:
                    map.put(etcmUiElPo.getUiElCode(),etcmHerbDiseasePo.getPValue());
                default:
            }

        }
        return map;
    }
}
